package com.zhang.mapper;

import com.zhang.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

@Mapper
public interface UserMapper {
    //根据用户名查询用户信息
    @Select("SELECT * FROM t_user where user_name = #{username}")
    User findByUserName(String username);

    //根据用户名查询用户详细信息（含角色）
    @Select("select u.id,u.password,u.user_name,u.true_name,u.remarks,r.name " +
            "from t_user_role ur " +
            "inner join t_user u on u.id=ur.user_id " +
            "inner join t_role r on r.id=ur.role_id " +
            "where user_name = #{username}")
    User findByUserNameWithRole(String username);


    //添加
    @Insert("insert into t_user(user_name,password) values(#{username},#{md5Password})")
    void add(String username, String md5Password);
}
